<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>LCV Framework: pic.c Quellcode</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Erzeugt von Doxygen 1.5.3 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Hauptseite</span></a></li>
    <li><a href="classes.html"><span>Datenstrukturen</span></a></li>
    <li class="current"><a href="files.html"><span>Dateien</span></a></li>
  </ul>
</div>
<h1>pic.c</h1><a href="pic_8c.html">gehe zur Dokumentation dieser Datei</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &lt;strings.h&gt;</span>
<a name="l00006"></a>00006 <span class="preprocessor">#include "<a class="code" href="lcv-structs_8h.html">lcv-structs.h</a>"</span>
<a name="l00007"></a>00007 <span class="preprocessor">#include "<a class="code" href="lcv-config_8h.html">lcv-config.h</a>"</span>
<a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="pic_8h.html">pic.h</a>"</span>
<a name="l00009"></a>00009 
<a name="l00010"></a><a class="code" href="pic_8c.html#3207c4aea24dad8d08ad3ded4f6ba876">00010</a> <a class="code" href="structlcv__picture.html" title="Bilderstruktur für unsigned 8-bit Bilder.">lcv_picture</a> <a class="code" href="dip_8c.html#3207c4aea24dad8d08ad3ded4f6ba876" title="Fertigt eine Kopie eines Bildes an, inklusive aller Parameter.">lcv_clone_picture</a>(<span class="keyword">const</span> <a class="code" href="structlcv__picture.html" title="Bilderstruktur für unsigned 8-bit Bilder.">lcv_picture</a>* pic)
<a name="l00011"></a>00011 {
<a name="l00012"></a>00012         <a class="code" href="structlcv__picture.html" title="Bilderstruktur für unsigned 8-bit Bilder.">lcv_picture</a> res_pic;
<a name="l00013"></a>00013         
<a name="l00014"></a>00014         res_pic.header_length = pic-&gt;header_length;
<a name="l00015"></a>00015         res_pic.<a class="code" href="structlcv__picture.html#d1fedb162e9fe3b19a1a70c24009a468">height</a> = pic-&gt;<a class="code" href="structlcv__picture.html#d1fedb162e9fe3b19a1a70c24009a468">height</a>;
<a name="l00016"></a>00016         res_pic.<a class="code" href="structlcv__picture.html#e83ac2254761aa2c6678f140565ddf52">width</a> = pic-&gt;<a class="code" href="structlcv__picture.html#e83ac2254761aa2c6678f140565ddf52">width</a>;
<a name="l00017"></a>00017         res_pic.<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a> = pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a>;
<a name="l00018"></a>00018         res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a> = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *)malloc(pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a>);
<a name="l00019"></a>00019         (void)memcpy(res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>, pic-&gt;<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>, pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a>);             
<a name="l00020"></a>00020         <span class="keywordflow">return</span> res_pic;                                                    
<a name="l00021"></a>00021 }
<a name="l00022"></a>00022 
<a name="l00023"></a><a class="code" href="pic_8c.html#7043e383be4ca95f8b41acee08c8eba9">00023</a> <span class="keywordtype">void</span> <a class="code" href="dip_8c.html#7043e383be4ca95f8b41acee08c8eba9">lcv_free_picture</a>(<a class="code" href="structlcv__picture.html" title="Bilderstruktur für unsigned 8-bit Bilder.">lcv_picture</a>* pic)
<a name="l00024"></a>00024 {
<a name="l00025"></a>00025         free(pic-&gt;<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>);
<a name="l00026"></a>00026         <span class="comment">//free(pic);    </span>
<a name="l00027"></a>00027 }
<a name="l00028"></a>00028 
<a name="l00029"></a><a class="code" href="pic_8c.html#d04debfd2555f7c1a887bb29f2d18e94">00029</a> <a class="code" href="structlcv__picture.html" title="Bilderstruktur für unsigned 8-bit Bilder.">lcv_picture</a> <a class="code" href="dip_8c.html#d04debfd2555f7c1a887bb29f2d18e94" title="Wandelt ein 24Bit BGR Bild in ein 8Bit Graustufenbild um Dieses Format wird nur intern...">lcv_rgb2gray</a>(<span class="keyword">const</span> <a class="code" href="structlcv__picture.html" title="Bilderstruktur für unsigned 8-bit Bilder.">lcv_picture</a>* pic)
<a name="l00030"></a>00030 {
<a name="l00031"></a>00031         <a class="code" href="structlcv__picture.html" title="Bilderstruktur für unsigned 8-bit Bilder.">lcv_picture</a> res_pic;
<a name="l00032"></a>00032         <span class="keywordtype">int</span>             gray_value;
<a name="l00033"></a>00033         <span class="keywordtype">int</span> i;  
<a name="l00034"></a>00034         
<a name="l00035"></a>00035         res_pic.<a class="code" href="structlcv__picture.html#d1fedb162e9fe3b19a1a70c24009a468">height</a> = pic-&gt;<a class="code" href="structlcv__picture.html#d1fedb162e9fe3b19a1a70c24009a468">height</a>;
<a name="l00036"></a>00036         res_pic.<a class="code" href="structlcv__picture.html#e83ac2254761aa2c6678f140565ddf52">width</a> = pic-&gt;<a class="code" href="structlcv__picture.html#e83ac2254761aa2c6678f140565ddf52">width</a>;     
<a name="l00037"></a>00037         res_pic.<a class="code" href="structlcv__picture.html#6bc2403299e0f61e26c4ade67d0ccacf">type</a> = <a class="code" href="lcv-structs_8h.html#b1860e6c3843411127d01321e616fd2439e6c4bfc9522eeea7cc640aa2e2d62a">IMG_GRAYSCALE</a>;
<a name="l00038"></a>00038         
<a name="l00039"></a>00039         
<a name="l00040"></a>00040         <span class="keywordflow">if</span>(pic-&gt;<a class="code" href="structlcv__picture.html#6bc2403299e0f61e26c4ade67d0ccacf">type</a> != <a class="code" href="lcv-structs_8h.html#b1860e6c3843411127d01321e616fd2439e6c4bfc9522eeea7cc640aa2e2d62a">IMG_GRAYSCALE</a>){
<a name="l00041"></a>00041                 res_pic.<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a> = pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a> / 3;
<a name="l00042"></a>00042                 res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a> = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)malloc(res_pic.<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a>);
<a name="l00043"></a>00043                 
<a name="l00044"></a>00044                 <span class="keywordflow">for</span>(i = 0; i &lt; pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a> ; i = i+3) {                 
<a name="l00045"></a>00045                         gray_value = (pic-&gt;<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>[i] + pic-&gt;<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>[i+1] + pic-&gt;<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>[i+2]) / 3;                      
<a name="l00046"></a>00046                         res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>[i/3] = gray_value;         
<a name="l00047"></a>00047                 }
<a name="l00048"></a>00048         }<span class="keywordflow">else</span>{
<a name="l00049"></a>00049                 res_pic.<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a> = pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a>;
<a name="l00050"></a>00050                 res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a> = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)malloc(pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a>);
<a name="l00051"></a>00051                 (void)memcpy(res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>, pic-&gt;<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>, pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a>);
<a name="l00052"></a>00052         }
<a name="l00053"></a>00053         <span class="keywordflow">return</span> res_pic;
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 
<a name="l00056"></a><a class="code" href="pic_8c.html#0e7dc12ed58b8d050583d2a8b78118a6">00056</a> <a class="code" href="structlcv__picture.html" title="Bilderstruktur für unsigned 8-bit Bilder.">lcv_picture</a> <a class="code" href="dip_8c.html#0e7dc12ed58b8d050583d2a8b78118a6" title="Wandelt ein 8Bit Graustufenbild in ein 24Bit BGR Bild um.">lcv_gray2rgb</a>(<span class="keyword">const</span> <a class="code" href="structlcv__picture.html" title="Bilderstruktur für unsigned 8-bit Bilder.">lcv_picture</a>* pic)
<a name="l00057"></a>00057 {
<a name="l00058"></a>00058         <a class="code" href="structlcv__picture.html" title="Bilderstruktur für unsigned 8-bit Bilder.">lcv_picture</a> res_pic;
<a name="l00059"></a>00059         <span class="keywordtype">int</span> i;  
<a name="l00060"></a>00060         
<a name="l00061"></a>00061         res_pic.<a class="code" href="structlcv__picture.html#d1fedb162e9fe3b19a1a70c24009a468">height</a> = pic-&gt;<a class="code" href="structlcv__picture.html#d1fedb162e9fe3b19a1a70c24009a468">height</a>;
<a name="l00062"></a>00062         res_pic.<a class="code" href="structlcv__picture.html#e83ac2254761aa2c6678f140565ddf52">width</a> = pic-&gt;<a class="code" href="structlcv__picture.html#e83ac2254761aa2c6678f140565ddf52">width</a>;     
<a name="l00063"></a>00063         res_pic.<a class="code" href="structlcv__picture.html#6bc2403299e0f61e26c4ade67d0ccacf">type</a> = <a class="code" href="lcv-structs_8h.html#b1860e6c3843411127d01321e616fd24ac1f6d8408e4448449149fc6ee90de65">IMG_BGR</a>;
<a name="l00064"></a>00064         
<a name="l00065"></a>00065         
<a name="l00066"></a>00066         <span class="keywordflow">if</span>(pic-&gt;<a class="code" href="structlcv__picture.html#6bc2403299e0f61e26c4ade67d0ccacf">type</a> != <a class="code" href="lcv-structs_8h.html#b1860e6c3843411127d01321e616fd24ac1f6d8408e4448449149fc6ee90de65">IMG_BGR</a>){
<a name="l00067"></a>00067                 res_pic.<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a> = pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a> * 3;
<a name="l00068"></a>00068                 res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a> = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)malloc(res_pic.<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a>);
<a name="l00069"></a>00069                 
<a name="l00070"></a>00070                 <span class="keywordflow">for</span>(i = 0; i &lt; res_pic.<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a> ; i = i+3) {      
<a name="l00071"></a>00071                         res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>[i] = pic-&gt;<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>[i/3];
<a name="l00072"></a>00072                         res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>[i+1] = pic-&gt;<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>[i/3];
<a name="l00073"></a>00073                         res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>[i+2] = pic-&gt;<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>[i/3];
<a name="l00074"></a>00074                 }
<a name="l00075"></a>00075         }<span class="keywordflow">else</span>{
<a name="l00076"></a>00076                 res_pic.<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a> = pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a>;
<a name="l00077"></a>00077                 res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a> = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)malloc(pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a>);
<a name="l00078"></a>00078                 (void)memcpy(res_pic.<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>, pic-&gt;<a class="code" href="structlcv__picture.html#2c2b64613effb4dccb763bb5ba4670f6">data</a>, pic-&gt;<a class="code" href="structlcv__picture.html#d1be6c681d8345ac3bbc3820ed8e3fee">length</a>);
<a name="l00079"></a>00079         }
<a name="l00080"></a>00080         <span class="keywordflow">return</span> res_pic;
<a name="l00081"></a>00081 }
</pre></div><hr size="1"><address style="text-align: right;"><small>Erzeugt am Thu Dec 13 11:25:43 2007 für LCV Framework von&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>
